<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box">
				<u-tabs-swiper activeColor="#f29100" ref="tabs" :list="list" :current="current" @change="change" :is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item class="swiper-item">
					<view class="order">
						<u-form-item label="编号:">{{ model.code }}</u-form-item>
						<u-form-item label="名称:">{{ model.name }}</u-form-item>
						<u-form-item label="图片:"><u-image v-for="(item, index) in model.urls" height="200rpx" :key="index" :src="item" mode="aspectFit"></u-image></u-form-item>
						<u-form-item label="类型:">{{ getTyp(model.type) }}</u-form-item>
						<u-form-item label="型号:">{{ model.model }}</u-form-item>
						<u-form-item label="厂商:">{{ model.manufacturer }}</u-form-item>
						<u-form-item label="地点:">{{ model.address }}</u-form-item>
						<u-form-item label="启用:">{{ model.usable }}</u-form-item>
						<u-form-item label="年限:">{{ model.durable }}</u-form-item>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<view class="order">
						<u-empty v-if="!list1.length" text="无数据" mode="page"></u-empty>
						<u-cell-group>
							<view v-for="(item, index) in list1" :key="index">
								<u-cell-item :title="item.trouble" :label="item.maintenance" :arrow="false">{{item.createdOn.substring(0, 16)}}</u-cell-item>
								<u-line></u-line>
							</view>
						</u-cell-group>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<view class="order">
						<u-empty v-if="!list2.length" text="无数据" mode="page"></u-empty>
						<u-cell-group>
							<view v-for="(item, index) in list2" :key="index">
								<u-cell-item :title="item.plan" :arrow="false">{{item.createdOn.substring(0, 10)}}</u-cell-item>
								<u-line></u-line>
							</view>
						</u-cell-group>
					</view>
				</swiper-item>
				<swiper-item class="swiper-item">
					<view class="order">
						<u-empty v-if="!list3.length" text="无数据" mode="page"></u-empty>
						<u-cell-group>
							<view v-for="(item, index) in list3" :key="index">
								<u-cell-item :title="item.plan" :arrow="false">{{item.createdOn.substring(0, 10)}}</u-cell-item>
								<u-line></u-line>
							</view>
						</u-cell-group>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			type: [],
			model: {},
			list: [
				{
					name: '基本信息'
				},
				{
					name: '报修记录'
				},
				{
					name: '巡检记录'
				},
				{
					name: '维保记录'
				}
			],
			list1: [],
			list2: [],
			list3: [],
			current: 0,
			swiperCurrent: 0,
			tabsHeight: 0,
			dx: 0
		};
	},
	onLoad(option) {
		this.request({
			url: 'BaseLabel/pages',
			data: {
				limit: 0
			},
			success: res => {
				this.type = res.data;
			}
		});
		this.request({
			url: 'BaseEquipment/detail',
			data: {
				id: option.id
			},
			success: res => {
				this.model = res.data;
				uni.setNavigationBarTitle({
					title: this.model.name
				});
			}
		});
	},
	methods: {
		getTyp(id) {
			let typ = this.type.find(m => m.value == id);
			if (typ != undefined) {
				return typ.label;
			} else {
				return '请选择分类';
			}
		},
		// tab栏切换
		change(index) {
			this.swiperCurrent = index;
			if (index == 1) {
				this.request({
					url: 'EamOrder/pages',
					data: {
						limit: 10,
						type: this.model.code
					},
					success: res => {
						this.list1 = res.data;
					}
				});
			}else if (index == 2) {
				this.request({
					url: 'EamPlanRecord/pages',
					data: {
						limit: 10,
						type: this.model.code
					},
					success: res => {
						this.list2 = res.data;
					}
				});
			}else if (index == 3) {
				this.request({
					url: 'EamMaintRecord/pages',
					data: {
						limit: 10,
						type: this.model.code
					},
					success: res => {
						this.list3 = res.data;
					}
				});
			}
		},
		transition({ detail: { dx } }) {
			this.$refs.tabs.setDx(dx);
		},
		animationfinish({ detail: { current } }) {
			this.$refs.tabs.setFinishCurrent(current);
			this.swiperCurrent = current;
			this.current = current;
		}
	}
};
</script>

<style>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
</style>

<style lang="scss" scoped>
.order {
	width: 710rpx;
	background-color: #ffffff;
	margin: 20rpx auto;
	border-radius: 20rpx;
	box-sizing: border-box;
	padding: 20rpx;
	font-size: 28rpx;
	.top {
		display: flex;
		justify-content: space-between;
		.left {
			display: flex;
			align-items: center;
			.store {
				margin: 0 10rpx;
				font-size: 32rpx;
				font-weight: bold;
			}
		}
		.right {
			color: $u-type-warning-dark;
		}
	}
	.item {
		display: flex;
		margin: 20rpx 0 0;
		.left {
			margin-right: 20rpx;
			image {
				width: 200rpx;
				height: 200rpx;
				border-radius: 10rpx;
			}
		}
		.content {
			.title {
				font-size: 28rpx;
				line-height: 50rpx;
			}
			.type {
				margin: 10rpx 0;
				font-size: 24rpx;
				color: $u-tips-color;
			}
			.delivery-time {
				color: #e5d001;
				font-size: 24rpx;
			}
		}
		.right {
			margin-left: 10rpx;
			padding-top: 20rpx;
			text-align: right;
			.decimal {
				font-size: 24rpx;
				margin-top: 4rpx;
			}
			.number {
				color: $u-tips-color;
				font-size: 24rpx;
			}
		}
	}
	.total {
		margin-top: 20rpx;
		text-align: right;
		font-size: 24rpx;
		.total-price {
			font-size: 32rpx;
		}
	}
	.bottom {
		display: flex;
		margin-top: 40rpx;
		padding: 0 10rpx;
		justify-content: space-between;
		align-items: center;
		.btn {
			line-height: 52rpx;
			width: 160rpx;
			border-radius: 26rpx;
			border: 2rpx solid $u-border-color;
			font-size: 26rpx;
			text-align: center;
			color: $u-type-info-dark;
		}
		.evaluate {
			color: $u-type-warning-dark;
			border-color: $u-type-warning-dark;
		}
	}
}
.centre {
	text-align: center;
	margin: 200rpx auto;
	font-size: 32rpx;
	image {
		width: 164rpx;
		height: 164rpx;
		border-radius: 50%;
		margin-bottom: 20rpx;
	}
	.tips {
		font-size: 24rpx;
		color: #999999;
		margin-top: 20rpx;
	}
	.btn {
		margin: 80rpx auto;
		width: 200rpx;
		border-radius: 32rpx;
		line-height: 64rpx;
		color: #ffffff;
		font-size: 26rpx;
		background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
	}
}
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
.swiper-box {
	flex: 1;
}
.swiper-item {
	height: 100%;
}
</style>
